from typing import Union, Optional

from models import execute

async def get_first_category() -> list:
    _, res = await execute('select id, title from good_cat where pid = 0 ')
    return res

async def get_second_category() -> list:
    _, res = await execute(
        '''
        select id, title, img from good_cat where id >= (SELECT floor(RAND()*(SELECT MAX(id) FROM
        good_cat WHERE pid in (select id from good_cat where pid = 0)))) and pid > 0;
        '''
    )
    return res

async def get_second_from_first(id) -> list:
    _, res = await execute('select id, title, img from good_cat where pid = %s;', (id,))
    return res

async def get_spu_from_second(id) -> list:
    _, res = await execute('select id, title, img, price from good where cid = %s', (id,))
    return res
